package com.booksystem.campuslibrarymanagementsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.booksystem.campuslibrarymanagementsystem.entity.UserTable;
import com.booksystem.campuslibrarymanagementsystem.mapper.UserTableMapper;
import com.booksystem.campuslibrarymanagementsystem.service.UserTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserTableServiceImpl extends ServiceImpl<UserTableMapper, UserTable> implements UserTableService {
    @Autowired
    UserTableMapper userTableMapper;

    @Override
    public UserTable queryByIds(int ids) {
        return userTableMapper.queryByIds(ids);
    }

    @Override
    public boolean upDataState(String ids, String state) {
        return userTableMapper.upDataState(ids,state);
    }

    @Override
    public UserTable selectLastIds() {
        return userTableMapper.selectLastIds();
    }

    @Override
    public boolean upDataName(String ids, String name) {
        return userTableMapper.upDataName(ids,name);
    }



    @Override
    public List<UserTable> selectListUser(String ids, String state, String name) {
        QueryWrapper<UserTable> queryWrapper = new QueryWrapper<>();
        // 构建查询条件
        if (ids != null && !ids.isEmpty()) {
            int id = Integer.parseInt(ids);
            queryWrapper.like("ids", id);
        }
        if (state != null && !state.isEmpty()) {
            queryWrapper.like("state", state);
        }
        if (name != null && !name.isEmpty()) {
            queryWrapper.like("name", name);
        }
        // 执行查询
        return userTableMapper.selectList(queryWrapper);
    }
}
